<!-- 首页 -->
<template>
	<view class="home-wrap u-m-b-20">
		<view v-if="isConnected && isRefresh" class="content-box">
			<!-- 导航栏 -->
			<home-head borderRadius="0" :isScorll="isScorll" :navTitle="initShop.name" :citys="citys"></home-head>
			<view class="search-box" v-show="!isScorll" :class="!isScorll?'activeopty':'activenone'">
				<view class="searchrong">
					<!-- 	<u-search placeholder="输入店铺名称" :disabled="true" shape="square" action-text=""
						:action-style="{'display':'none'}" :animation="true" class="u-flex u-row-center"
						@click="$Router.push('/pages/public/search')"></u-search> -->
					<u-search shape="square" action-text="" :action-style="{'display':'none'}" v-model="searchVals"
						bgColor="#ffffff" padding="30rpx" placeholder="输入店铺名称" height="64" @search="onSearch"
						@clear="clearSearch">
					</u-search>
					<u-icon name="scan" class="scan" color="#333333" @click="toscan"></u-icon>
				</view>

			</view>
			<!-- 自定义模块 -->
			<view class="template-box">
				<block v-for="(item, index) in homeTemplate" :key="item.id">
					<!-- 滑动宫格 -->
					<!--  <sh-grid-swiper v-if="item.type === 'menu'" :list="item.content.list" ></sh-grid-swiper> -->
					<!-- 轮播 -->
					<sh-banner v-if="item.type === 'banner'" :Px="item.content.x" :Py="item.content.y"
						:borderRadius="item.content.radius" :height="300" :list="item.content.list"></sh-banner>




					<!-- 搜索 -->
					<!--					<sh-search v-if="item.type === 'search'"></sh-search>-->



					<!--					&lt;!&ndash; 推荐商品 &ndash;&gt;-->
					<!--					<sh-hot-goods v-if="item.type === 'goods-list' || item.type === 'goods-group'" :detail="item.content"></sh-hot-goods>-->
					<!--					&lt;!&ndash; 广告魔方 &ndash;&gt;-->
					<!--					<sh-adv v-if="item.type === 'adv'" :detail="item.content"></sh-adv>-->

					<!--					&lt;!&ndash; 优惠券 &ndash;&gt;-->
					<!--					<sh-coupon v-if="item.type === 'coupons'" :detail="item.content"></sh-coupon>-->
					<!-- 惠享权益 -->

					<!-- 秒杀-->
					<!-- 					<view class="activity" v-if="item.type === 'groupon'"
						style=" background: url('https://duomi.bigchun.com/images/Frame111.png') no-repeat!important;background-size: 100%;">	 -->

					<view class="" v-if="item.type === 'groupon'">
						<view class="activity">
							<view class="huixiang-box">
								<view class="huixiang-box-title">
									<view class="huixiang-title-text">
										惠享权益
									</view>
									<view class="head-more u-flex u-col-center"
										@click="$Router.push('/pages/index/serveList')">
										<text class="more-text">全部</text>
										<u-icon name="arrow-right" size="20" color="#999999"></u-icon>
									</view>
								</view>
								<view class="huixiang-card" @click="gotoService(1)">
									<view class="huixiang-card-left">
										<image class="huixiang-card-img"
											src="https://duomi.bigchun.com/images/huixiang1.png"></image>
										<view class="huixiang-card-text">
											<text>吃喝玩乐</text>
											<text>玩转本地生活！</text>
										</view>
									</view>
									<view class="huixaing-card-right">
										查看详情
									</view>
								</view>
								<view class="huixiang-tool">
									<view class="huixaing-tool-item" @click="gotoService(4)">
										<image src="https://duomi.bigchun.com/images/hx_icon1.png"></image>
										<text>健康保健</text>
									</view>
									<view class="huixaing-tool-item" @click="gotoService(2)">
										<image src="https://duomi.bigchun.com/images/hx_icon2.png"></image>
										<text>多米服务</text>
									</view>
									<view class="huixaing-tool-item" @click="gotoService(3)">
										<image src="https://duomi.bigchun.com/images/hx_icon3.png"></image>
										<text>多米教育</text>
									</view>
								</view>
								<view v-if="isVip == 0" class="huixiang-vip" @click="$Router.push('/pages/index/membeRecharge')" style=" background: 													url('https://duomi.bigchun.com/imgs/bg.png') no-repeat!important;background-size:100% !important;
		background-position:center!important;">
									<view class="huixiang-vip-left">
										<image class="huixiang-vip-img"
											src="https://duomi.bigchun.com/images/hx_icon5.png"></image>
										<view class="huixiang-vip-text">
											<text>多米会员 更多权益
											</text>
											<text>欢迎成为多米之家成员</text>
										</view>
									</view>
									<view class="huixiang-vip-right">
										开通
									</view>
								</view>
							</view>
							<huixuan-exercise class="seckill-card-xianshi" :title="'镇店之宝'" :isshouye="true"
								:detail="item.content" :isVip="isVip"></huixuan-exercise>
						</view>
					</view>

					<!--					&lt;!&ndash; 拼团 &ndash;&gt;-->
					<!--					<sh-groupon v-if="item.type === 'groupon'" :detail="item.content"></sh-groupon>-->
					<!--					&lt;!&ndash; 富文本 &ndash;&gt;-->
					<!--					<sh-richtext v-if="item.type === 'rich-text'" :richId="item.content.id"></sh-richtext>-->
					<!-- 功能标题 -->
					<!--					<sh-title-card v-if="item.type === 'title-block'" :title="item.content.name" :bgImage="item.content.image" :titleColor="item.content.color"></sh-title-card>-->
					<!--					&lt;!&ndash; 直播 &ndash;&gt;-->
					<!--					&lt;!&ndash; #ifdef MP-WEIXIN &ndash;&gt;-->
					<!--					<sh-live v-if="item.type === 'live' && HAS_LIVE" :detail="item.content"></sh-live>-->
					<!--					&lt;!&ndash; #endif &ndash;&gt;-->
				</block>
			</view>

			<!-- 分类选项卡 	v-if="categoryTabsData && categoryTabsData.category_arr && categoryTabsData.category_arr.length"-->
			<sh-category-tabs ref="tabchoose" :enable="enable" :styleType="categoryTabsData.style"
				:tabsList="categoryTabsData.category_arr"></sh-category-tabs>
			<!-- 悬浮按钮 -->
			<shopro-float-btn v-if="is_finshed"></shopro-float-btn>
			<!-- 连续弹窗提醒 -->
			<!--			<shopro-notice-modal v-if="!showPrivacy && isLogin"></shopro-notice-modal>-->
			<!-- 隐私协议 -->
			<!--			&lt;!&ndash; #ifdef APP-PLUS &ndash;&gt;-->
			<!--			<privacy-modal v-if="initShop && initShop.name" v-model="showPrivacy"></privacy-modal>-->
			<!--			&lt;!&ndash; #endif &ndash;&gt;-->
			<!--			&lt;!&ndash; #ifdef H5 &ndash;&gt;-->
			<!--			<view class="tabbar-hack" style="height: 120rpx; width:100%;"></view>-->
			<!--			&lt;!&ndash; #endif &ndash;&gt;-->
		</view>
		<!-- <shopro-tabbar></shopro-tabbar> -->
	</view>
</template>

<script>
	import shBanner from './components/sh-banner.vue';
	import shGridSwiper from './components/sh-grid-swiper.vue';
	import shHotGoods from './components/sh-hot-goods.vue';
	import shAdv from './components/sh-adv.vue';
	import shCoupon from './components/sh-coupon.vue';
	import shSeckill from './components/sh-seckill.vue';
	import shGroupon from './components/sh-groupon.vue';
	import shRichtext from './components/sh-richtext.vue';
	import shTitleCard from './components/sh-title-card.vue';
	import shSearch from './components/sh-search.vue';
	import shCategoryTabs from './components/sh-category-tabs.vue';
	import homeHead from './index/home-head.vue';
	// #ifdef MP-WEIXIN
	import {
		HAS_LIVE
	} from '@/env';
	import shLive from './components/sh-live.vue';
	// #endif

	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	import log from "../order/after-sale/log";
	export default {
		components: {
			shBanner,
			shGridSwiper,
			shGroupon,
			shHotGoods,
			shAdv,
			shCoupon,
			shSeckill,
			shRichtext,
			shTitleCard,
			shSearch,
			shCategoryTabs,
			homeHead,
			// #ifdef MP-WEIXIN
			shLive
			// #endif
		},
		data() {
			return {
				// #ifdef MP-WEIXIN
				HAS_LIVE: HAS_LIVE,
				// #endif
				isRefresh: true,
				enable: false, //是否开启吸顶。
				isConnected: true, //是否有网
				showPrivacy: false, //协议
				isScorll: false,
				citys: this.$store.state.shopro.citys,
				searchVals: '',
				service: [],
				isVip: 0,
        is_finshed:false,
			};
		},
		computed: {
			...mapGetters(['initShop', 'homeTemplate', 'hasTemplate', 'isLogin', 'latitude', 'longitude']),
			// 头部模块数据
			headSwiperList() {
				if (this.latitude) {
					return this.latitude;
				}
			},
			// 分类选项卡数据
			categoryTabsData() {
				if (this.homeTemplate?.length) {
					return this.homeTemplate[this.homeTemplate.length - 1]?.content;
				}
			},
		},
		onPullDownRefresh() {
			this.init();
		},
		onPageScroll(e) {
			this.isScorll = e.scrollTop > 50 ? true : false;
		},
		onShow() {
			let that = this;
			that.enable = true;
			// 网络变化检测
			uni.onNetworkStatusChange(res => {
				that.isConnected = res.isConnected;
				res.isConnected && that.init();
				that.isLogin && that.getCartList();
			});
      console.log("=====出现了",this.$store.state.shopro.citys)
			that.getServive()
			that.getVip()
		},
		onHide() {
			this.enable = false;
		},
		onLoad() {
			let that = this;
			// #ifdef APP-VUE
			// app隐私协议弹窗
			if (!plus.runtime.isAgreePrivacy()) {
				that.showPrivacy = true;
				that.showNoticeModal = false;
			}
			// #endif
		},
		created() {

		},
		watch: {
			'categoryTabsData.category_arr': {
				immediate: true,
        deep:true,
				handler(val) {
					var that = this;
					that.citys = uni.getStorageSync("city"); //城市名称
					console.log("=this.citys ===", that.citys)
					console.log(uni.getStorageSync("latitude"), uni.getStorageSync("longitude"), "=========latitude", this
						.latitude, "=========longitude", this.longitude, )
					console.log("ns===========", val)
				}
			},
      '$store.state.shopro.pink_time':{
        //对数据执行操作
        deep:true,
        immediate: true,
        handler(val,old) {
          if (val>0 && this.$store.state.shopro.is_join == 0 && this.$store.state.shopro.vip_pink_id) {
            this.is_finshed = true
          } else {
            this.is_finshed = false
          }
        }
      },
      '$store.state.shopro.is_join':{
			  deep:true,
        immediate: true,
        handler(val,old) {
         if(val == 0&&this.$store.state.shopro.vip_pink_id&&this.$store.state.shopro.pink_time>0){
            this.is_finshed = true
         }else{
           this.is_finshed = false
         }
        }
      },
      '$store.state.shopro.vip_pink_id':{
        immediate: true,
        deep:true,
        handler(val,old) {
          if(val&&this.$store.state.shopro.is_join == 0&&this.$store.state.shopro.pink_time>0){
            this.is_finshed = true
          }else{
            this.is_finshed = false
          }
        }
      },
      '$store.state.shopro.citys':{
        immediate: true,
        deep:true,
        handler(val,old) {
          if(val){
            this.citys = val
          }else{
            this.citys = old
          }
        }
      }
		},
		methods: {
			...mapActions(['appInit', 'getTemplate', 'getCartList']),
			// 初始化
			init() {
				this.isRefresh = false;
				return Promise.all([this.getTemplate()]).then(() => {
					uni.stopPullDownRefresh();
					this.isRefresh = true;
				});
			},
			getVip() {
				this.$https('user.isVip').then(res => {
					if (res.code === 1) {
						this.isVip = res.data;
					}
				})
			},
			// 获取服务
			getServive() {
				console.log("获取服务")
				this.$https('common.template_service', {}).then(res => {
					console.log(res)
					if (res) {
						this.service = res.data
					}
				})
			},
			//绑定设备调用微信扫码
			toscan() {
				// 允许从相机和相册扫码
				var that = this;
				uni.scanCode({
					success: function(res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						let formdata = {
							pc_id: res.result,
							authorization: uni.getStorageSync('token')
						}
					}
				});
			},
			// 清除输入框
			clearSearch() {
				this.searchVals = '';
			},
			// 搜索
			onSearch(e) {
				this.$Router.push(`/pages/goods/list?keywords=${e}`);
				this.searchVals = '';
			},
			// 服务
			gotoService(id) {
				console.log("index:", id)
        if(id == 2){
          this.$Router.push(`/pages/index/serveList?id=${id}`);
        }else if(id == 1){
          this.$Router.push(`/pages/goods/list?shop_type=play`);
        }else{
          this.$Router.push(`/pages/index/serve?id=${id}`);
        }
			}
		}
	};
</script>

<style lang="scss" scoped>
	.activity {
		background-size: 100% 100%;
		margin: 22rpx 22rpx;
		padding: 10rpx 22rpx;
		border-radius: 28rpx;
	}

	.search-box {
		width: 100%;
		height: 98rpx;
		margin-top: -6rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: url("https://duomi.bigchun.com/images/Frame108.png") no-repeat;
		position: relative;

		.searchrong {
			width: 95%;
			position: relative;
			margin: 0 auto;

			.scan {
				position: absolute;
				right: 20rpx;
				top: 20rpx;
				z-index: 1222;
			}
		}
	}

	.activeopty {
		opacity: 1;
		transition: opacity 0.8s;
	}

	.activenone {
		opacity: 0;
		transition: opacity 0.8s;
	}

	.content-box {
		background: linear-gradient(180deg, #FFFFFF 0%, #F8F8F8 100%);
	}

	.huixiang-box {
		background-color: #FFFFFF;
		padding: 30rpx 0;
		margin-bottom: 20rpx;
	}

	.huixiang-box-title {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.huixiang-title-text {
		font-weight: 700;
		font-size: 36rpx;
	}

	.head-more {
		.more-text {
			font-size: 22rpx;
			font-weight: 500;
			color: #999999;
		}

		.more-icon {
			color: #333333;
			font-size: 24rpx;
		}
	}

	.huixiang-card {
		margin-bottom: 40rpx;
		margin-top: 40rpx;
		padding: 4rpx 10rpx;
		border: 1px solid #FFE4E4;
		border-radius: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.huixiang-card-left {
		display: flex;
		align-items: center;
	}

	.huixiang-card-img {
		width: 122rpx;
		height: 122rpx;
	}

	.huixiang-card-text {
		display: flex;
		flex-direction: column;
		margin-left: 14rpx;
		color: #FC5351;
	}

	.huixiang-card-text text:first-child {
		font-size: 32rpx;
		font-weight: 700;
	}

	.huixiang-card-text text:last-child {
		font-size: 28rpx;
		font-weight: 400;
		margin-top: 8rpx;
	}

	.huixaing-card-right {
		width: 148rpx;
		height: 52rpx;
		line-height: 52rpx;
		text-align: center;
		background: #FC5351;
		border-radius: 54rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		margin-right: 10rpx;
	}

	.huixiang-tool {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.huixaing-tool-item {
		display: flex;
		width: 33%;
		padding: 30rpx 24rpx;
		background: rgba(255, 110, 109, 0.1);
		border-radius: 8rpx;
	}

	.huixaing-tool-item image {
		width: 36rpx;
		height: 36rpx;
	}

	.huixaing-tool-item text {
		font-size: 30rpx;
		font-weight: 700;
		margin-left: 10rpx;
	}

	.huixiang-vip {
		margin-top: 20rpx;
		width: 100%;
		height: 160rpx;
		display: flex;
		align-items: center;
		padding: 40rpx 20rpx;
		justify-content: space-between;
	}

	.huixiang-vip-left {
		display: flex;
		align-items: center;
	}

	.huixiang-vip-img {
		width: 52rpx;
		height: 52rpx;
	}

	.huixiang-vip-text {
		display: flex;
		flex-direction: column;
		margin-left: 12rpx;
		color: #C08549;
	}

	.huixiang-vip-text text:first-child {
		font-size: 30rpx;
		font-weight: 700;
	}

	.huixiang-vip-text text:last-child {
		font-size: 26rpx;
		font-weight: 400;
		margin-top: 4rpx;
	}

	.huixiang-vip-right {
		width: 96rpx;
		height: 52rpx;
		line-height: 52rpx;
		text-align: center;
		background: #D99F65;
		border-radius: 54rpx;
		opacity: 1;
		font-size: 24rpx;
		font-weight: bold;
		color: #FFFFFF;
	}
</style>
